{%     set loopback_ip_list = device_abstract_config.get('system', {}).get('loopback_ip_list', []) %}
{%     if loopback_ip_list|length > 0 %}
{%         set loopback_ip = loopback_ip_list[0] %}
{%         if loopback_ip %}
set groups {{cfg_group}} routing-options router-id {{loopback_ip}}
set groups {{cfg_group}} routing-options route-distinguisher-id {{loopback_ip}}
{%         endif %}
{%     endif %}

{%     set rib_name = 'bgp.rtarget.0' %}
{%     set resolution_rib = 'inet.0' %}
{%     for bgp in device_abstract_config.get('bgp', []) %}
{%         if feature in bgp.get('comment', '') %}
{%             set route_distinguisher = bgp.get('ip_address') %}
set groups {{cfg_group}} routing-options autonomous-system {{bgp.autonomous_system}}
set groups {{cfg_group}} routing-options resolution rib {{rib_name}} resolution-ribs {{resolution_rib}}
{%             set bgp_group_name = bgp.get('name') %}
{%             set bgp_group_type = bgp.get('type_') %}
{%             set hold_time = bgp.get('hold_time') %}
{%             set families = bgp.get('families', []) %}
set groups {{cfg_group}} protocols bgp group {{bgp_group_name}} type {{bgp_group_type}}
{%             set cluster_id = bgp.get('cluster_id') %}
{%             if cluster_id != None %}
set groups {{cfg_group}} protocols bgp group {{bgp_group_name}} cluster {{cluster_id}}
{%             endif %}
set groups {{cfg_group}} protocols bgp group {{bgp_group_name}} hold-time {{hold_time}}
set groups {{cfg_group}} protocols bgp group {{bgp_group_name}} multipath
set groups {{cfg_group}} protocols bgp group {{bgp_group_name}} local-address {{route_distinguisher}}
set groups {{cfg_group}} protocols bgp group {{bgp_group_name}} vpn-apply-export
{%             for fam in families %}
{%                 if fam == 'route-target' %}
set groups {{cfg_group}} protocols bgp group {{bgp_group_name}} family {{fam}}
{%                 endif %}
{%                 if fam == 'evpn' %}
set groups {{cfg_group}} protocols bgp group {{bgp_group_name}} family {{fam}} signaling
{%                 endif %}
{%                 if bgp_group_type == 'internal' %}
{%                     if fam.startswith('inet') %}
set groups {{cfg_group}} policy-options policy-statement _contrail_ibgp_export_policy term {{fam}} from family {{fam}}
set groups {{cfg_group}} policy-options policy-statement _contrail_ibgp_export_policy term {{fam}} then next-hop self
set groups {{cfg_group}} protocols bgp group {{bgp_group_name}} export _contrail_ibgp_export_policy
{%                     endif %}
{%                 endif %}
{%             endfor %}
{%             for peer in bgp.get('peers', []) %}
{%                 set peer_addr = peer.get('ip_address') %}
{%                 set peer_as = peer.get('autonomous_system') %}
set groups {{cfg_group}} protocols bgp group {{bgp_group_name}} neighbor {{peer_addr}} peer-as {{peer_as}}
{%             endfor %}
{%         endif %}
{%     endfor %}
